home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / EntityListDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  3.7 KB  |  132 lines

  1. // EntityListDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Radiant.h"
  6. #include "EntityListDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CEntityListDlg dialog
  16.  
  17.  
  18. CEntityListDlg::CEntityListDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CEntityListDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CEntityListDlg)
  22.     //}}AFX_DATA_INIT
  23. }
  24.  
  25.  
  26. void CEntityListDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28.     CDialog::DoDataExchange(pDX);
  29.     //{{AFX_DATA_MAP(CEntityListDlg)
  30.     DDX_Control(pDX, IDC_LIST_ENTITY, m_lstEntity);
  31.     DDX_Control(pDX, IDC_TREE_ENTITY, m_treeEntity);
  32.     //}}AFX_DATA_MAP
  33. }
  34.  
  35.  
  36. BEGIN_MESSAGE_MAP(CEntityListDlg, CDialog)
  37.     //{{AFX_MSG_MAP(CEntityListDlg)
  38.     ON_BN_CLICKED(IDSELECT, OnSelect)
  39.     ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_ENTITY, OnSelchangedTreeEntity)
  40.     ON_NOTIFY(NM_DBLCLK, IDC_TREE_ENTITY, OnDblclkTreeEntity)
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CEntityListDlg message handlers
  46.  
  47. void CEntityListDlg::OnSelect() 
  48. {
  49.   HTREEITEM hItem = m_treeEntity.GetSelectedItem();
  50.   if (hItem)
  51.   {
  52.     entity_t* pEntity = reinterpret_cast<entity_t*>(m_treeEntity.GetItemData(hItem));
  53.     if (pEntity)
  54.     {
  55.       Select_Deselect();
  56.         Select_Brush (pEntity->brushes.onext);
  57.     }
  58.     }
  59.   Sys_UpdateWindows(W_ALL);
  60. }
  61.  
  62. BOOL CEntityListDlg::OnInitDialog() 
  63. {
  64.     CDialog::OnInitDialog();
  65.     
  66.   CMapStringToPtr mapEntity;
  67.  
  68.   HTREEITEM hParent = m_treeEntity.InsertItem(world_entity->eclass->name);
  69.   HTREEITEM hChild = m_treeEntity.InsertItem(world_entity->eclass->name, hParent);
  70.   m_treeEntity.SetItemData(hChild, reinterpret_cast<DWORD>(world_entity));
  71.  
  72.     for (entity_t* pEntity=entities.next ; pEntity != &entities ; pEntity=pEntity->next)
  73.     {
  74.     hParent = NULL;
  75.     if (mapEntity.Lookup(pEntity->eclass->name, reinterpret_cast<void*&>(hParent)) == FALSE)
  76.     {
  77.       hParent = m_treeEntity.InsertItem(pEntity->eclass->name);
  78.       mapEntity.SetAt(pEntity->eclass->name, reinterpret_cast<void*>(hParent));
  79.     }
  80.     hChild = m_treeEntity.InsertItem(pEntity->eclass->name, hParent);
  81.     m_treeEntity.SetItemData(hChild, reinterpret_cast<DWORD>(pEntity));
  82.   }
  83.  
  84.   CRect rct;
  85.   m_lstEntity.GetClientRect(rct);
  86.   m_lstEntity.InsertColumn(0, "Key", LVCFMT_LEFT, rct.Width() / 2);
  87.   m_lstEntity.InsertColumn(1, "Value", LVCFMT_LEFT, rct.Width() / 2);
  88.   m_lstEntity.DeleteColumn(2);
  89.   UpdateData(FALSE);
  90.     
  91.     return TRUE;  // return TRUE unless you set the focus to a control
  92.                   // EXCEPTION: OCX Property Pages should return FALSE
  93. }
  94.  
  95. void CEntityListDlg::OnSelchangedTreeEntity(NMHDR* pNMHDR, LRESULT* pResult) 
  96. {
  97.     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  98.   HTREEITEM hItem = m_treeEntity.GetSelectedItem();
  99.   m_lstEntity.DeleteAllItems();
  100.   if (hItem)
  101.   {
  102.     CString strList;
  103.     entity_t* pEntity = reinterpret_cast<entity_t*>(m_treeEntity.GetItemData(hItem));
  104.     if (pEntity)
  105.     {
  106.         for (epair_t* pEpair = pEntity->epairs ; pEpair ; pEpair = pEpair->next)
  107.       {
  108.             if (strlen(pEpair->key) > 8)
  109.           strList.Format("%s\t%s", pEpair->key, pEpair->value);
  110.         else
  111.           strList.Format("%s\t\t%s", pEpair->key, pEpair->value);
  112.         int nParent = m_lstEntity.InsertItem(0, pEpair->key);
  113.         m_lstEntity.SetItem(nParent, 1, LVIF_TEXT, pEpair->value, 0, 0, 0, reinterpret_cast<DWORD>(pEntity));
  114.  
  115.       }
  116.     }
  117.     }
  118.     *pResult = 0;
  119. }
  120.  
  121. void CEntityListDlg::OnDblclkListInfo() 
  122. {
  123.     // TODO: Add your control notification handler code here
  124.     
  125. }
  126.  
  127. void CEntityListDlg::OnDblclkTreeEntity(NMHDR* pNMHDR, LRESULT* pResult) 
  128. {
  129.   OnSelect();
  130.     *pResult = 0;
  131. }
  132.